package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsCategoryMapper;
import com.qf.pojo.DtsCategory;
import com.qf.service.DtsCategoryService;
import com.qf.vo.CatVo;
import com.qf.vo.CategorySellAmts;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @author Cc
 * @version 1.0
 */
@Service
public class DtsCategoryServiceImpl implements DtsCategoryService {

    @Autowired
    private DtsCategoryMapper dtsCategoryMapper;


    @Override
    public List<CategorySellAmts> findGoodsCategoryAndTotal() {
        return dtsCategoryMapper.findGoodsCategoryAndTotal();
    }

    @Override
    public IPage<DtsCategory> findAll(Integer page, Integer limit, String sort, String order) {
        return dtsCategoryMapper.selectPage(new Page(page,limit),
                new QueryWrapper<DtsCategory>()
                        .eq("deleted", false)
                        .orderBy(!StringUtils.isEmpty(sort), "ASC".equalsIgnoreCase(order), sort));
    }

    @Override
    public List<CatVo> l1() {
        return dtsCategoryMapper.L1List();
    }

    @Override
    public void create(DtsCategory dtsCategory) {
        dtsCategoryMapper.insert(dtsCategory);
    }

    @Override
    public void update(DtsCategory dtsCategory) {
        dtsCategoryMapper.updateById(dtsCategory);
    }

    @Override
    public void delete(Integer id) {
        dtsCategoryMapper.deleteUpdateById(id);
    }
}
